import http from '../util/http.js';

export default {

    getProductList:()=>{
        return http({
            method:"get",
            url:"api/product/list"
        });
    },
    getProductPage:(page)=>{
        return http({
            method:"get",
            url:"api/product/page",
            params:page
        });
    },
    deleteProduct:(id)=>{
        return http({
            method:"delete",
            url:"api/product/"+id,
        });
    },
    addProduct:(obj)=>{
        return http({
           method:"post",
           url:"api/product",
            data: obj,
            //后台是用requesbody接受，所以需要是json数据 保持前后台一致
            headers:{
                'Content-Type':'application/json'
            }
        });
    },
    editProduct:(obj)=>{
        return http({
            method:"put",
            url:"api/product",
            data: obj,
            //后台是用requesbody接受，所以需要是json数据 保持前后台一致
            headers:{
                'Content-Type':'application/json'
            }
        });
    },
    /*对商品的数据操作*/
    productGetOne:(id)=>{
        return http({url:'api/product/'+id,method:'get'});
    },
    productGetPage:async (current,size)=>{
        const val= await http({url:'api/product/page',method:'get',
           //param提供表单数据
            params:{current,size}
        });
        console.log("---------------");
        console.log(val);
        return val;
    },

    productDelete:(id)=>{
        http({
            url:"api/product/"+id,
            method:'delete'
        });
    },
    productEdit:(obj)=>{
        console.log(obj);
        return http({
            url:"api/product/",
            method:'PUT',
            //提交json数据，必须有header
            data: obj,
            headers: {
                //定义将数据以json的形式传入后台(java)
                'Content-Type': 'application/json'
            }
        });
    },
    }